Advanced
googleAnalyticsR 2

Mark Edmondson (@HoloMarkeD)

September 12th, 2019 - New York

Session 2
Using the data: Statistical Modeling and Shiny

Structuring your script

Input, Tidy, Model, Output

Use RStudio projects!

  • scripts/
  • data/

Scripts

In scripts/ folder:

  • scripts/input.R - download and gather data
  • scripts/tidy.R - process data into usable by model step
  • scripts/model.R - create models
  • scripts/out.R - make plots, Rmd, final outputs

Data

In data/ folder:

  • data/raw/ - any raw data files (CSVs etc)
  • data/cache/ - API cache files
  • data/output/ - clean tidy files

Use saveRDS/readRDS rather than write.csv()/read.csv() - 10xquicker

ga_model

Why ga_model()?

  • Advanced R users sharing results quickly with newbie R users
  • Reproduceable objects
  • Enables quick Shiny deployments
  • Tweet embeds

ga_model example

ga_model example output

Decomposition example

Decomposition example output

ga_model object structure

  • decomp_ga$data_f = function to get data
  • decomp_ga$model_f = function to model data
  • decomp_ga$output_f = function to plot data
## function(df, ...){
##     decompose(ts(df$sessions, frequency = 7))
## }

Build your own ga_model - step 1

  • Create a data fetching function

Build your own ga_model - step 2

  • Create a modelling function

Build your own ga_model - step 3

  • Create an output function

Build your own ga_model - step 4

  • Build model object with ga_model_make()

Build your own ga_model - step 5 (optional)

  • Build model object with Shiny outputs

Build your own ga_model - step 6

  • Save model object to a .gamr object

Use your ga_model

Shiny deployments

YouTube video!

A bit out of date!

Creating Shiny deployments - auth

Creating Shiny deployments - ga_model

R libraries for googleAnalyticsR analysis